import { BasicColumn, FormSchema } from '/@/components/Table';
import { getDictDetailListApi } from '/@/api/sys/dict';
import { DataStatusEnum, ScopeTypeEnum } from '/@/enums/sysEnum';
import { TreeSelect } from 'ant-design-vue';

export const Permission = {
  ADD: 'role.add',
  EDIT: 'role.edit',
  DEL: 'role.del',
};

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 200,
  },
  {
    title: '编号',
    dataIndex: 'code',
  },
  {
    title: '状态',
    dataIndex: 'state',
  },
  {
    title: '数据权限',
    dataIndex: 'scope',
  },
  {
    title: '备注',
    dataIndex: 'remark',
  },
  {
    title: '创建时间',
    dataIndex: 'createAt',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'state',
    label: '状态',
    component: 'ApiSelect',
    componentProps: {
      api: getDictDetailListApi,
      params: {
        code: 'data_status',
      },
    },
    colProps: { span: 6 },
  },
];

function handleChangeScope(data) {
  console.log('change', data);
}

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    rules: [
      { required: true, message: '请填写名称' },
      { max: 100, message: '名称最多100字' },
    ],
  },
  {
    field: 'code',
    label: '编号',
    component: 'Input',
    rules: [
      { required: true, message: '请填写编号' },
      { max: 100, message: '编号最多100字' },
    ],
  },
  {
    field: 'scope',
    label: '数据权限',
    component: 'ApiRadioGroup',
    componentProps: ({ formModel }) => {
      return {
        api: getDictDetailListApi,
        params: {
          code: 'scope_type',
        },
        isBtn: true,
        onChange: () => {
          delete formModel.orgIds;
        }
      }
    },
    defaultValue: ScopeTypeEnum.ALL,
  },
  {
    field: 'orgIds',
    label: '自定义数据范围',
    component: 'TreeSelect',
    ifShow: (data) => {
      return data.values.scope == ScopeTypeEnum.CUSTOM;
    },
    componentProps: {
      multiple: true,
      treeDefaultExpandAll: true,
      treeCheckable: true,
      treeCheckStrictly: false,
      showCheckedStrategy: TreeSelect.SHOW_ALL,
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'state',
    label: '状态',
    component: 'ApiRadioGroup',
    componentProps: {
      api: getDictDetailListApi,
      params: {
        code: 'data_status',
      },
      isBtn: true,
    },
    defaultValue: DataStatusEnum.NORMAL,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    rules: [{ max: 255, message: '编号最多255字' }],
  },
  {
    field: 'menuIds',
    label: '',
    slot: 'menuIds',
    component: 'Input',
  },
];
